﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.IO;

namespace CardClass
{
    /// <summary>
    /// Interaction logic for CardControlRole.xaml
    /// </summary>
    public partial class CardControlRole : UserControl
    {
        bool bHide = true;

        SolidColorBrush brush_border = new SolidColorBrush();

        public CardControlRole()
        {
            InitializeComponent();

            // Default layout
            this.Width = 80;
            this.Height = 100;

            Rotate.CenterX = this.Width / 2;
            Rotate.CenterY = this.Height / 2;

            this.MouseEnter += new MouseEventHandler(CardControl_MouseEnter);
            this.MouseLeave += new MouseEventHandler(CardControl_MouseLeave);
            this.Cursor = Cursors.Hand;
            this.MouseLeftButtonDown += new MouseButtonEventHandler(CardControl_MouseLeftButtonDown);
        }

        void CardControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!bHide)
            {
                this.role.Visibility = Visibility.Visible;
            }
            else
            {
                this.role.Visibility = Visibility.Collapsed;
            }
            bHide = !bHide;
        }

        void CardControl_MouseLeave(object sender, MouseEventArgs e)
        {
            BorderColor = Color.FromArgb(255, 0, 0, 0);
        }
        void CardControl_MouseEnter(object sender, MouseEventArgs e)
        {
            BorderColor = Color.FromArgb(255, 255, 0, 255);
        }

        public virtual new double Height
        {
            get { return LayoutRoot.Height; }
            set
            {
                LayoutRoot.Height = value;
                border.Height = value;
            }
        }
        public virtual new double Width
        {
            get { return LayoutRoot.Width; }
            set
            {
                LayoutRoot.Width = value;
                border.Width = value;
            }
        }
        public String RoleText
        {
            get { return role.Text; }
            set { role.Text = value; }
        }
        public Color BorderColor
        {
            get { return brush_border.Color; }
            set
            {
                brush_border.Color = value;
                border.Stroke = brush_border;
            }
        }
        public void SetURI(string path)
        {
            string str = Assembly.GetAssembly(typeof(CardControlAction)).Location;
            str = System.IO.Path.GetDirectoryName(str) + "\\" + path;
            Uri uri = new Uri(str, UriKind.Absolute);
            logo.Source = new BitmapImage(uri);
        }
        public double Left
        {
            get { return Translate.X; }
            set { Translate.X = value; }
        }
        public double Top
        {
            get { return Translate.Y; }
            set { Translate.Y = value; }
        }
        public double Angle
        {
            get { return Rotate.Angle; }
            set { Rotate.Angle = value; }
        }

    }
}

